package jcl;

import robocode.control.snapshot.IRobotSnapshot;
import robocode.control.testing.RobotTestBed;
import robocode.control.events.BattleCompletedEvent;
import robocode.control.events.TurnEndedEvent;
import static org.junit.Assert.assertTrue;

/**
 * Tests to see if MajorTom runs into walls.
 * 
 * @author Jerry Lau
 * 
 */
public class TestMajorTomHitWall extends RobotTestBed {

  boolean hitWall = false;

  /**
   * Gets the name of the robots which will battle.
   * 
   * @return The list of robots in the match.
   */
  public String getRobotNames() {
    return "sample.SittingDuck,jcl.MajorTom";
  }

  /**
   * Runs for 10 rounds.
   * 
   * @return Number of rounds
   */
  public int getNumRounds() {
    return 10;
  }

  /**
   * Checks if the robot runs into a wall.
   * 
   * @param event Battle info
   */
  public void onTurnEnded(TurnEndedEvent event) {
    IRobotSnapshot robot = event.getTurnSnapshot().getRobots()[1];
    double x = robot.getX();
    double y = robot.getY();

    // Check to see if the robot ever runs into a wall
    if ((x < 40) || (x > (width - 40)) || (y < 40) || (y > (height - 40))) {
      hitWall = true;
    }
  }

  /**
   * After battle, check if the robot hit a wall.
   * 
   * @param event Completed battle info
   */
  public void onBattleCompleted(BattleCompletedEvent event) {
    assertTrue("Check if bot ever hits a wall", hitWall);
  }

}
